#!/bin/sh

declare APP_NAME=$1

if [ ! -n "${APP_NAME}" ]; then
  echo " APP_NAME is empty, exit."
  exit 0
else
  echo " APP_NAME is ${APP_NAME}, continue..."
fi

# 定义一个工作目录
declare path=$(cd `dirname $0`; pwd)
echo "current path is  :" ${path} 

echo ""
echo "${APP_NAME} shuting down..."
echo ""

declare BASE_PATH=${path};
declare APP_PATH=${BASE_PATH}/${APP_NAME};

cd ${APP_PATH}
echo "enter ${APP_PATH}"

/usr/local/jdk/bin/java -Xms4096m -Xmx4096m -XX:+PrintGCDetails -Xloggc:/home/logs/app/server/${APP_NAME}/gc.log -XX:+PrintGCTimeStamps -jar ${APP_PATH}/current/${APP_NAME}-server-1.0-SNAPSHOT/${APP_NAME}-server-1.0-SNAPSHOT.jar &

cd ${path}
echo "return ${path}"

# echo $!
echo "started ok. pid: ${!}"

declare  PID_FILE=${BASE_PATH}/${APP_NAME}.pid;

echo "pid文件：${PID_FILE}"

if [ ! -f "$PID_FILE" ]; then  
touch "$PID_FILE"  
fi  
echo "${!}" > ${PID_FILE}